package com.nacos.novelbookserver.service.impl;

import com.nacos.novelbookserver.dao.NovelBookDao;
import com.nacos.novelbookserver.service.NovelBookService;
import com.nacos.novelcommon.entity.NovelBook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (NovelBook)表服务实现类
 *
 * @author 刘会发
 * @since 2020-04-01 21:30:38
 */
@Service("novelBookService")
public class NovelBookServiceImpl implements NovelBookService {
    @Resource
    private NovelBookDao novelBookDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public NovelBook queryById(Integer id) {
        return this.novelBookDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<NovelBook> queryAllByLimit(int offset, int limit) {
        return this.novelBookDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param novelBook 实例对象
     * @return 实例对象
     */
    @Override
    public NovelBook insert(NovelBook novelBook) {
        this.novelBookDao.insert(novelBook);
        return novelBook;
    }

    /**
     * 修改数据
     *
     * @param novelBook 实例对象
     * @return 实例对象
     */
    @Override
    public NovelBook update(NovelBook novelBook) {
        this.novelBookDao.update(novelBook);
        return this.queryById(novelBook.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.novelBookDao.deleteById(id) > 0;
    }
}